import type { ApiResponse } from '../utils/http/types'
import type {
  ProductInfoResult,
  OrderInfoTypeResult,
  OrderInfoParams,
  PayOption,
  PayInfo,
  PaymentTypeResult,
  PaymentTypeParams,
  PaymentInfoTypeParams,
  PaymentInfoTypeResult
} from '../types/index'

import http from '../utils/http/index'

/**
 * @description 收银台接口地址
 */
export enum ApisCashier {
  /**
   * 通过租户id和产品线id获取租户logo
   */
  GetLogo = '/kukebasesystem/index/product/getProductDetail',
  /**
   * 根据产品线id和支付类型获取产品线是否配置了该支付方式
   */
  GetIsSettingPayConfig = '/kukebasesystem/payment/ksmerchant/isExistConfig',
  /**
   *  调起支付
   */
  OnPay = '/kukeordercenter/checkoutCounter/v1/pay',
  /**
   * 收银台通过订单sn获取商品信息
   */
  GetOrderDetails = '/kukeordercenter/checkoutCounter/v1/getOrderDetails',
  /**
   *  收银台通过订单sns获取商品信息 购物车
   */
  GetOrderDetailsByCart = '/kukeordercenter/checkoutCounter/v2/getOrderDetails',
  /**
   * 获取当前的微信appid
   */
  GetWxAppId = '/kukebasesystem/thirdParty/v1/getWxAppId',
  /**
   * 通过授权code 获取openid
   */
  GetOpenId = '/kukecoreuser/wap/woa/oauth/wxOpenid',
  /** 查询订单状态
   * wap端使用
   */
  GetOrderPayStatusWap = '/kukeonlineorder/wap/order/getPayStatus',
  /** 查询订单状态
   * pc 端使用
   */
  GetOrderPayStatusPc = '/kukeonlineorder/pc/order/getPayStatus',
  /**
   * 调起支付 购物车
   */
  OnPayByCart = '/kukeordercenter/checkoutCounter/v2/pay'
}

/*
 * 获取产品线logo
 * */
export const getProjectLogo = () => {
  return http.request<ApiResponse<ProductInfoResult>>('post', ApisCashier.GetLogo, {})
}

/*
 * 获取支付信息
 * */
export const getPayInfo = (data: PayOption) => {
  return http.request<ApiResponse<PayInfo>>('post', ApisCashier.OnPay, { data })
}

/*
 * 获取订单信息
 * */
export const getOrderInfo = (data: OrderInfoParams) => {
  return http.request<ApiResponse<OrderInfoTypeResult>>('post', ApisCashier.GetOrderDetails, {
    data
  })
}
/*
 * 获取购物车订单信息
 * */
export const getOrderCardInfo = (data: OrderInfoParams) => {
  return http.request<ApiResponse<OrderInfoTypeResult>>('post', ApisCashier.GetOrderDetailsByCart, {
    data
  })
}

/*
 * 查询订单状态 wap使用
 * */
export const getOrderStatus = (data: PaymentInfoTypeParams) => {
  return http.request<ApiResponse<PaymentInfoTypeResult>>(
    'post',
    ApisCashier.GetOrderPayStatusWap,
    {
      data,
      customConfig: {
        hideLoading: true
      }
    }
  )
}

/*
 * 查询订单状态 pc使用
 * */
export const getOrderStatusPc = (data: PaymentInfoTypeParams) => {
  return http.request<ApiResponse<PaymentInfoTypeResult>>('post', ApisCashier.GetOrderPayStatusPc, {
    data,
    customConfig: {
      loading: false
    }
  })
}

/*
 * 获取当前的微信appid
 * */
export const getWxAppId = (data: any) => {
  return http.request<ApiResponse<any>>('post', ApisCashier.GetWxAppId, { data })
}

/*
 * 通过公共号授权code获取微信id
 * */
export const getCodeOpenIdInfo = (data: { code: string }) => {
  return http.request<ApiResponse<any>>('post', ApisCashier.GetOpenId, {
    data
  })
}

/*
 * 获取购物车的支付信息
 * */
export const getCardPayInfo = (data: PayOption) => {
  return http.request<ApiResponse<PayInfo>>('post', ApisCashier.OnPayByCart, { data })
}
/*
 * 获取是否配置支付的信息
 * */
export const getIsSettingPay = (data: PaymentTypeParams) => {
  return http.request<ApiResponse<PaymentTypeResult>>('post', ApisCashier.GetIsSettingPayConfig, {
    data
  })
}
